package com.css.common.core.config.valid;

import com.css.common.core.annotation.ValiCode;
import com.css.common.core.utils.BaseUtil;
import lombok.extern.slf4j.Slf4j;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @description: 码值合法性校验器
 * @Author chenhui
 * @Date 2024/11/12 15:41
 */
@Slf4j
public class ValiCodeValidator implements ConstraintValidator<ValiCode,String> {
        private ValiCode ann;
        @Override
        public void initialize(ValiCode ann) {//初始化方法
            this.ann=ann;
        }
        @Override
        public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
            if(BaseUtil.isNull(value)) return false;
            try {
                if(this.ann.vals().getMethod("getMc",String.class).invoke(null,value) !=null) return true;
            } catch (Exception e) {
                log.info("ValiCodeValidator异常",e);
            }
            return false;//返回true校验通过，false校验不通过
        }
}